package com.example.assignment5.service;

import com.example.assignment5.exception.CustomException;
import com.example.assignment5.sub;
import com.example.assignment5.repository.supRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class supServiceIm implements supService {

    @Autowired
    supRepository supplierRepository;

    @Override
    public void add(sub supplier) {
        sub supplier1=supplierRepository.findById(supplier.getId()).orElse(null);
        if(supplier1!=null){
            throw new CustomException("重复添加");
        }
        supplierRepository.save(supplier);
    }


    @Override
    public sub getById(Long id) {
        return supplierRepository.findById(id).orElse(null);
    }
}
